/*
 * @Author: szx
 * @Date: 2022-04-22 13:09:31
 * @LastEditTime: 2022-04-22 13:19:45
 * @Description:
 * @FilePath: \leetcode\剑指offerII\091\091.js
 */
/**
 * @param {number[][]} costs
 * @return {number}
 */
var minCost = function (costs) {
    const n = costs.length;
    const dp = new Array(n + 1).fill(0).map(() => new Array(3).fill(0));
    for (let i = 0; i < n; i++) {
        const num = costs[i];
        dp[i + 1][0] = Math.min(dp[i][1], dp[i][2]) + num[0];
        dp[i + 1][1] = Math.min(dp[i][0], dp[i][2]) + num[1];
        dp[i + 1][2] = Math.min(dp[i][0], dp[i][1]) + num[2];
    }
    return Math.min(...dp[n]);
};
var minCost = function (costs) {
    const n = costs.length;
    let dp0 = 0,
        dp1 = 0,
        dp2 = 0,
        tmp0,
        tmp1,
        tmp2;
    for (let i = 0; i < n; i++) {
        const num = costs[i];
        tmp0 = Math.min(dp1, dp2) + num[0];
        tmp1 = Math.min(dp0, dp2) + num[1];
        tmp2 = Math.min(dp0, dp1) + num[2];
        dp0 = tmp0;
        dp1 = tmp1;
        dp2 = tmp2;
    }
    return Math.min(tmp0, Math.min(tmp1, tmp2));
};
